package com.pets.web.service.impl;

import com.mchange.util.AlreadyExistsException;
import com.pets.common.utils.StringUtils;
import com.pets.web.entity.PetsPlatform;
import com.pets.web.mapper.PetsPlatformMapper;
import com.pets.web.service.IPetsPlatformService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平台表 服务实现类
 * </p>
 *
 * @author zhurenwang
 * @since 2024-05-26
 */
@Service
public class PetsPlatformServiceImpl extends ServiceImpl<PetsPlatformMapper, PetsPlatform> implements IPetsPlatformService {

    @Override
    public List<PetsPlatform> list(PetsPlatform petsPlatform) {
        return lambdaQuery()
                .like(StringUtils.isNotEmpty(petsPlatform.getName()), PetsPlatform::getName, petsPlatform.getName())
                .list();
    }

    @Override
    public int add(PetsPlatform petsPlatform) {
        boolean exists = lambdaQuery().eq(PetsPlatform::getPfCode, petsPlatform.getPfCode()).exists();
        if (exists){
            throw new IllegalArgumentException("code已存在");
        }
        petsPlatform.setPfCode(petsPlatform.getPfCode().trim());
        return baseMapper.insert(petsPlatform);
    }

    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }
}
